package DateStructure.MyLink;

public class LinkClass<K> {
    private Integer num = 0;
    private Node<K> last = null;
    private Node<K> next = null;
    private Node<K> first = null;

    public void add(K value) {
        Node<K> node = new Node<>(last, next, value);
        if(last == null) {
            last = node;
            first = node;
        } else {
            last.setNext(node);
        }
        num++;
    }

    public K get(Integer id) {
        Node<K> node = first;
        if(id > num) {
            System.out.println("out of length!");
            return null;
        } else {
            for (int i = 1; i < num; i++) {
                node = node.getNext();
            }
        }
        return node.getValue();
    }
}
